package com.github.postsanf.yinian.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.github.postsanf.yinian.R;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.List;

public class StealPhotosPicAdapter extends BaseAdapter {
    private Context mContext;
    private List<String> mItems = new ArrayList<>();

    public StealPhotosPicAdapter(Context context, List<String> mItems) {
        this.mContext = context;
        this.mItems = mItems;
    }

    public int getCount() {
        return mItems.size();
    }

    public Object getItem(int position) {
        return 9;
    }

    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from
                    (mContext).inflate(R.layout.stealphotospic_item, null, false);
            holder.iv = (ImageView) convertView.findViewById(R.id.steal_photo_iv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final String listItems = mItems.get(position);
//        Uri uri = Uri.parse("res://" +
//                mContext.getPackageName() +
//                "/" + R.drawable.steal_pic_deault);
        holder.iv.setImageResource(R.drawable.steal_pic_deault);
        final ImageView iv2 = holder.iv;
        holder.iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                ImageOptHelper.showFrescoNative(Uri.parse(listItems), iv2, mContext);
                ImageLoader.getInstance().displayImage(listItems, iv2);
            }
        });
        return convertView;
    }

    private class ViewHolder {
        ImageView iv;
    }


}
